package com.codingfuture.erp_system.service.impl;

import com.codingfuture.erp_system.dto.GoodsDto;
import com.codingfuture.erp_system.entity.Goods;
import com.codingfuture.erp_system.entity.GoodsType;
import com.codingfuture.erp_system.mapper.GoodsMapper;
import com.codingfuture.erp_system.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public Goods findById(Integer id) {
        return goodsMapper.findById(id);
    }


    @Override
    public List<Goods> findByAll(GoodsDto goodsDto) {
        return goodsMapper.findByAll(goodsDto);
    }

    @Override
    public Goods findByName(String name) {
        return goodsMapper.findByName(name);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insert(Goods goods) {
        return goodsMapper.insert(goods) != 0;
    }

    @Override
    public List<GoodsType> findAll() {
        return goodsMapper.finAll();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean update(Goods goods) {
        return goodsMapper.update(goods) != 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean delete(Integer id) {
        return goodsMapper.delete(id) != 0;
    }
}
